home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / network / lattice / portlib.lzh / PORTLIB / RTENT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-29  |  790 b   |  52 lines

  1. /*
  2.  * Routing table access functions for MintNet. (w) 1994 Kay Roemer.
  3.  */
  4.  
  5. #include <unistd.h>
  6. #include <fcntl.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netinet/in.h>
  10. #include <net/if.h>
  11. #include <net/route.h>
  12. #include "rtent.h"
  13.  
  14. #define _PATH_DEV_ROUTE    "/dev/route"
  15.  
  16. struct route_info {
  17.     char        nif[IFNAMSIZ];
  18.     struct rtentry    rt;
  19. };
  20.  
  21. static int rtfd = -1;
  22. static struct route_info rtent;
  23.  
  24. void
  25. setrtent (void)
  26. {
  27.     if (rtfd < 0) {
  28.         rtfd = open (_PATH_DEV_ROUTE, O_RDONLY);
  29.     }
  30. }
  31.  
  32. void
  33. endrtent (void)
  34. {
  35.     if (rtfd >= 0)
  36.         close (rtfd);
  37.     rtfd = -1;
  38. }
  39.  
  40. struct rtentry *
  41. getrtent (void)
  42. {
  43.     int r;
  44.  
  45.     if (rtfd < 0)
  46.         return 0;
  47.     r = read (rtfd, &rtent, sizeof (rtent));
  48.     if (r != sizeof (rtent))
  49.         return 0;
  50.     return &rtent.rt;
  51. }
  52.